# -*- encoding=utf8 -*-
"""
RedFlag-TC0000104  （拍摄进入装饰页）使用字体+颜色功能功能
使用颜色+字体+气泡功能场景
保存场景
"""
__author__ = "ldm"

import sys
import os

# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *
from device_elements import *

auto_setup(__file__)
shooter = CameraVideoShooter()

case_text = "这是一条测试数据"

log("--------------------------------使用颜色+字体+气泡功能场景--------------------------------------")
"""
拍摄视频进入装饰页
点击文字
输入指定的文案
使用一个字体
点击颜色
使用一个颜色
点击气泡
使用一个气泡
点击保存
断言
"""

shooter.enter_photography_decoration_page()
shooter.click_element(decoration_page_text_function)
shooter.input_text_in_element(decoration_page_text_function_input, case_text)
shooter.click_element(decoration_page_text_function_font[1])
shooter.click_element(decoration_page_text_function_colour)
shooter.click_element(decoration_page_text_function_choice_colour[1])
shooter.click_element(decoration_page_text_function_bubble)
shooter.click_element(decoration_page_text_function_choice_bubble[1])
shooter.click_element(decoration_page_text_function_confirm)
shooter.assert_image_exists(r"tpl1751372950339.png", "断言失败，预期图片并未出现",record_pos=(-0.009, -0.056), resolution=(1224, 2700),threshold=0.7)


log("--------------------------------保存场景--------------------------------------")
"""
点击保存
等待
点击设视频彩铃
等待
点击播放
截屏
获取手机品牌
进入对应手机相册
进入保存的视频
截图
断言
"""

shooter.click_element(decoration_page_save)
shooter.wait_for_element_disappearance(decoration_page_save_animation, 120)
shooter.click_element(set_video_ringtone)
shooter.wait_for_element_appearance(set_video_ringtone_play, 30)
shooter.click_element(set_video_ringtone_play)
photo1 = shooter.capture_screenshot("TC0000104A.png")

# 关闭应用
stop_app(UGC_package_name)

# 获取手机品牌
phone_model = shooter.get_phone_model()


# ---------------------------------华为P50----------------------------------
if phone_model:
    if "huawei" in phone_model.lower() or "华为" in phone_model:
        shooter.click_element(Comes_photo_album_huawei)
        shooter.click_element(Comes_photo_album_all_photos[1].child("com.huawei.photos:id/album_cover_image"))
        shooter.click_element(Comes_photo_album_select[0])
        touch((0.5,0.2))
        sleep(2.0)
        photo2 = shooter.capture_screenshot("TC0000104B.png")
        shooter.assert_images_equal(photo1, photo2, "断言失败，图片比对不成功")
        stop_app("com.huawei.photos")
    elif "vivo" in phone_model.lower():
        shooter.click_element(Comes_photo_album_vivo)
        shooter.click_element(Comes_photo_album_all_photos_vivo)
        shooter.click_element(Comes_photo_album_frist_video_vivo.child())
        touch((0.5, 0.2))
        sleep(2.0)
        photo2 = shooter.capture_screenshot("TC0000104B.png")
        shooter.assert_images_equal(photo1, photo2, "断言失败，图片比对不成功")
        stop_app("com.vivo.gallery")
    else:
        print(f"不支持的手机品牌: {phone_model}")
else:
    print("无法获取手机型号信息，跳过断言操作")

